package thread;

import java.util.concurrent.Semaphore;

public class demo13 {
    //permits指定信号量的个数
    static Semaphore semaphore = new Semaphore(3);

    public static void main(String[] args) throws InterruptedException {
        //通过p操作-->acquire来获取信号量
        semaphore.acquire();
        System.out.println("获取信号量");

        semaphore.acquire();
        System.out.println("获取信号量");

        semaphore.acquire();
        System.out.println("获取信号量");
        //acquire获取信号量时候如果Semaphore已经没有信号量了就会阻塞等待
        //当有其他线程执行v操作--->release释放信号量,acquire才能获取到信号量
        //释放资源
        semaphore.release();

        semaphore.acquire();
        System.out.println("aaaaaaaaaaaa");
    }
}
